function gadget:GetInfo()
return {
		name = "movementsubsystems.lua",
		desc = "adds gather command",
		author = "tomr13",
		date = "10/11/2011",
		license = "public domain",
		layer = 1,
		enabled = true,
}
end
local MovementShips={}

MovementShips[UnitDefNames["gatherer"].id]={
  movement=1
}

local Ships = {
	[UnitDefNames.gatherer.id] = "gatherer",
	[UnitDefNames.heavyattackship.id] = "heavyattackship",
	[UnitDefNames.lightattackship.id] = "lightattackship",
}

local CMD_MAX_MOVEMENT_SUBSYSTEM = 33612


local echo = Spring.Echo

if not GG.attUnits then
	GG.attUnits = {}
end

local units = {}

Movement_Subsystem_Toggle = {
		id=CMD_MAX_MOVEMENT_SUBSYSTEM,
		type=CMDTYPE.ICON,
			name="Boost",
			texture="&.9x.9&bitmaps/icons/blank.tif&bitmaps/icons/burrow.png",
			tooltip="Gathers wreckage.",
			action="movementsubsystem"
		}

if (not gadgetHandler:IsSyncedCode()) then 
 return false
end

local function ChangeSubSystems(unitID, health, movement, damage)

	Spring.SetUnitRulesParam(unitID,"Health_Subsystem", health)
	Spring.SetUnitRulesParam(unitID,"Movement_Subsystem", movement)
	Spring.SetUnitRulesParam(unitID,"Damage_Subsystem", damage)
	
	local a = Spring.GetUnitRulesParam(unitID,"Health_Subsystem")
	local b = Spring.GetUnitRulesParam(unitID,"Movement_Subsystem")
	local c = Spring.GetUnitRulesParam(unitID,"Damage_Subsystem")
	--Spring.Echo("Subsystems Set: " .. a .. " " .. b .. " " .. c)
end

function gadget:CommandFallback(unitID, unitDefID, teamID, cmdID, cmdParams, cmdOptions)
 if (cmdID~=CMD_MAX_MOVEMENT_SUBSYSTEM) then
  return false
 end
 --echo("HELLO WORLD")
 if(not Ships[unitDefID]) then
   return true, true --this shouldn't happen and I'm not sure but I think that this removes the command from the list
 end
 ChangeSubSystems(unitID,100,100,100)
end

function gadget:GameFrame(frame)    
	if frame % 90 == 4 then  
		local allUnits = Spring.GetAllUnits()
		for _, unitID in ipairs(units) do				
			local a =  Spring.GetUnitRulesParam(unitID,"Movement_Subsystem")
			if(a) then
				--echo("MOVEMENT " .. a)
				if a > 0 then
					a = a/10
				end
				if a < 1 then
					a = 1
				end
				Spring.SetUnitCOBValue(unitID, COB.MAX_SPEED, 150000*a)
			end
		end	
	end
 end

 function gadget:UnitDestroyed(unitID, unitDefID, team)
    if(Ships[unitDefID]) then
		--echo("SDFSDFSDFSDFSDFSDKFSLDFJLSKDJFSLDFJS")
		table.remove(units, unitID)
	end
end

function gadget:UnitCreated(unitID, unitDefID, unitTeam)	
	if(Ships[unitDefID]) then
		Spring.InsertUnitCmdDesc(unitID, Movement_Subsystem_Toggle)
		ChangeSubSystems(unitID, 33,33,33)
		--Spring.Echo(" SDFSDF" .. Spring.GetUnitCOBValue(unitID, COB.MAX_SPEED))
		--Spring.SetUnitCOBValue(unitID, COB.MAX_SPEED, 4000)
		Spring.SetUnitCOBValue(unitID, COB.MAX_SPEED, 40000)
		table.insert(units, unitID)
	end
end

function gadget:Initialize()
 gadgetHandler:RegisterCMDID(CMD_MAX_MOVEMENT_SUBSYSTEM)
end